import getpass
import os

from langchain_chroma import Chroma
from langchain_community.chat_message_histories import ChatMessageHistory
from fastapi import FastAPI
from langchain_core.documents import Document
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables import RunnableWithMessageHistory
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langserve import add_routes
from sqlalchemy.testing.suite.test_reflection import metadata

os.environ["http_proxy"] = "127.0.0.1:7890"
os.environ["https_proxy"] = "127.0.0.1:7890"

os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_PROJECT"] = "langchainDemo"
os.environ["LANGCHAIN_API_KEY"] = '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'

#聊天机器人案例
#1、创建大模型
# model = ChatOpenAI(model='gpt-4o-mini')

#准备测试数据，假设我们提供的额文档数据如下：
documents = [
    Document(
        page_content="狗是伟大的伴侣，以其忠诚和友好性而受到好评。",
        metadata = {"source":"哺乳动物宠物文档"},
    ),
    Document(
        page_content="猫是独立的宠物，通常喜欢自己的空间。",
        metadata = {"source":"哺乳动物宠物文档"},
    ),
    Document(
        page_content="金鱼是初学者的流行宠物，需要相对简单的护理。",
        metadata = {"source":"哺乳动物宠物文档"},
    ),
    Document(
        page_content="鹦鹉是聪明的鸟类，能给模仿人类的语言。",
        metadata = {"source":"哺乳动物宠物文档"},
    ),
    Document(
        page_content="兔子是社交的动物，需要足够的空间跳跃。",
        metadata = {"source":"哺乳动物宠物文档"},
    ),
]
#实例化一个向量数据库=向量空间
vector_store = Chroma.from_documents(documents, embedding=OpenAIEmbeddings())
#相似度查询:返回相似的分数，分数越低相似度越高
print(vector_store.similarity_search_with_score('咖啡猫'))